import { View, Text } from '@tarojs/components'
import Taro from '@tarojs/taro'
import React from 'react'
import CImage from '../CImage/index'
import './index.scss'
import dateFormat from '@/utils/dateFormat'
interface ICard {
  data: {
    questionImg?: string
    questionName?: string
    questionSubtitle?: string
    courseName?: string
    courseImg?: string
    courseSubtitle?: string
    price?: string
    gmtCreate?: Date
    id?: number
    userQuestionId?: number
    questionId?: number
    actualPrice?: number
    orderEndDate?: string
    payTime?: string
    orderId: string
  }
  tabstatus?: number //tab状态  0:1:2
  type?: number // 栏目   type:1：我的测评 2：我的课程  3：我的订单
  goPay?: (orderId) => void
}

export default function CorderCard(params: ICard) {
  const system = Taro.getStorageSync('system')
  let {
    questionImg = '',
    questionName = '',
    questionSubtitle = '',
    courseName = '',
    courseSubtitle = '',
    courseImg = '',
    price = 0,
    gmtCreate = '',
    id = 0,
    userQuestionId = 0,
    questionId = 0,
    actualPrice = 0,
    orderEndDate = '',
    payTime = '',
    orderId = 0,
  } = params.data
  //  newTime = new Date(oldTime)
  gmtCreate = dateFormat(gmtCreate)
  let tabstatus = Number(params.tabstatus)
  let type = params.type
  let goPay = params.goPay

  // 去订单详情
  function gotoOrderDetail() {
    Taro.navigateTo({
      url: `/pages/My/MyOrder/OrderDetail/index?orderId=${orderId}`,
    })
  }
  // 去支付
  //  async function goPay() {
  //     await pay_api(sn).then(({ result, data }) => {
  //       if (result === 1999) {
  //         Taro.requestPayment({
  //           timeStamp: data.timeStamp,
  //           nonceStr: data.nonceStr,
  //           package: data.package,
  //           signType: data.signType,
  //           paySign: data.paySign,
  //           success: (res) => {
  //             Taro.showToast({
  //               title: '支付成功！',
  //             })
  //             get_order_data()
  //           },
  //           fail: function (res) {
  //             console.log(res)
  //           },
  //         })
  //       }
  //     })
  //   }

  // 去测试
  function gotoTest() {
    Taro.navigateTo({
      url: `/pages/Home/TestQuestions/index?id=${questionId}`,
    })
  }
  // 查勘报告
  function gotoReport() {
    Taro.navigateTo({
      url: `/pages/Home/HomeEvaluationResults/index?questionId=${questionId}&userQuestionId=${userQuestionId}&id=${id}&showType=1`,
    })
  }
  // 去观看
  function gotoVideo() {
    Taro.navigateTo({
      url: `/pages/College/VideoPlay/index?id=` + id,
    })
  }
  // 去评价
  function gotoComment() {
    Taro.navigateTo({
      url: '/pages/My/MyCourses/Evaluate/index?id=' + id,
    })
  }
  return (
    <View className='content_4'>
      <View className='orderNO'>订单编号：:{orderId}</View>
      <View className='content_5'>
        <View className='left'>
          <View>
            <Text className='title'>{courseName || questionName || ''}</Text>
          </View>
          <View>
            <Text className='noto'>{courseSubtitle || questionSubtitle}</Text>
          </View>
          <View className='price'>{system.indexOf('iOS') < 0 ? (price || actualPrice ? '￥' + (price || actualPrice) : '') : '免费'}</View>
          {gmtCreate && (
            <View className='timer'>
              <Text>创建时间：</Text>
              <Text>{gmtCreate}</Text>
            </View>
          )}
          {payTime && (
            <View className='timer'>
              <Text>支付时间：</Text>
              <Text>{payTime}</Text>
            </View>
          )}
        </View>
        {type === 3 ? (
          ''
        ) : (
          <View className='right'>
            <CImage src={courseImg || questionImg}></CImage>
          </View>
        )}
      </View>
      {system.indexOf('iOS') < 0 ? (
        // 我的测评
        type === 1 ? (
          <View className='footer'>
            {tabstatus === 0 ? (
              <View className='btn' onClick={gotoTest}>
                去测试
              </View>
            ) : (
              <View className='btn' onClick={gotoReport}>
                查看报告
              </View>
            )}
          </View>
        ) : type === 2 ? (
          // 我的课程
          tabstatus === 0 ? (
            <View className='footer'>
              <View className='btn' onClick={gotoVideo}>
                去观看
              </View>
            </View>
          ) : tabstatus === 1 ? (
            ''
          ) : (
            <View className='footer'>
              <View className='btn' onClick={gotoComment}>
                去评价
              </View>
            </View>
          )
        ) : (
          // 我的订单
          <View className='footer'>
            {tabstatus === 0 ? (
              <View className='btn' onClick={goPay}>
                去支付
              </View>
            ) : (
              <View className='btn' onClick={gotoOrderDetail}>
                {/* 订单详情 */}
                查看详情
              </View>
            )}
          </View>
        )
      ) : (
        ''
      )}
    </View>
  )
}
